from django.http import HttpResponse
from django.shortcuts import render
from django.db import connection
from .models import Book
# Create your views here.

def index(request):
    # 获取游标对象
    cursor = connection.cursor()
    # 拿到游标对象后执行sql语句
    cursor.execute("select * from book_book")
    # 获取所有的数据
    rows = cursor.fetchall()
    # 遍历查询到的数据
    for row in rows:
        print(row)
    return HttpResponse("OK")


def add_view(request):
    book = Book(name='python开发指南',author='zhj',price=1200)
    book.save()
    return HttpResponse("新增图书成功！")

def query_book(request):
    books = Book.objects.all()
    for book in books:
        print(book.id,book.name,book.pub_time,book.price)
    return HttpResponse("查找成功")